<?php

declare(strict_types=1);

/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://doc.hyperf.io
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
 */

use Hyperf\HttpServer\Router\Router;
use \App\Middleware\AuthUser;

Router::addRoute(['GET', 'POST', 'HEAD'], '/', 'App\Controller\IndexController@index');


Router::addServer('ws', function () {
    Router::get('/', 'App\Controller\WebSocketController');
});


Router::addGroup('/api', function () {
    Router::addGroup('/articles/', function () {
        Router::addRoute(['GET', 'POST'], 'lists', 'App\Controller\ArticleController@lists');
        Router::addRoute(['DELETE', 'GET'], 'batch-del', 'App\Controller\ArticleController@batchDelete');
        Router::addRoute(['PUT', 'GET'], 'status', 'App\Controller\ArticleController@toggleStatus');
        Router::addRoute(['POST', 'GET'], 'save/{id}', 'App\Controller\ArticleController@save');
        Router::addRoute(['GET'], 'detail/{id}', 'App\Controller\ArticleController@detail');
    });
    Router::addGroup('/users/', function () {
        Router::addRoute(['GET', 'POST'], 'list', 'App\Controller\UserController@index');
        Router::addRoute(['POST', 'GET'], 'save/{id}', 'App\Controller\UserController@save');
        Router::addRoute(['GET'], 'detail/{id}', 'App\Controller\UserController@detail');
        Router::addRoute(['DELETE', 'GET'], 'batch-del', 'App\Controller\UserController@batchDelete');
    });

    Router::addGroup('/roles/', function () {
        Router::addRoute(['GET', 'POST'], 'list', 'App\Controller\RoleController@index');
        Router::addRoute(['POST', 'GET'], 'save/{id}', 'App\Controller\RoleController@save');
        Router::addRoute(['GET'], 'detail/{id}', 'App\Controller\RoleController@detail');
        Router::addRoute(['DELETE', 'GET'], 'batch-del', 'App\Controller\RoleController@batchDelete');
        Router::addRoute(['GET'], '{roleId}/menus', 'App\Controller\RoleController@roleMenus');
        Router::addRoute(['GET'], 'all-menus', 'App\Controller\RoleController@allMenus');
        Router::addRoute(['GET', 'PUT'], '{roleId}/menus-save', 'App\Controller\RoleController@saveMenus');
    });

    Router::addGroup('/menus/', function () {
        Router::addRoute(['GET'], 'list', 'App\Controller\MenuController@index');
        Router::addRoute(['POST', 'GET'], 'save/{id}', 'App\Controller\MenuController@save');
        Router::addRoute(['GET'], 'detail/{id}', 'App\Controller\MenuController@detail');
        Router::addRoute(['DELETE', 'GET'], 'batch-del', 'App\Controller\MenuController@batchDelete');
    });


    Router::addGroup('/chat/', function () {
        Router::get('records', 'App\Controller\ChatController@records');
    });
}, ['middleware' => [AuthUser::class]]);

